package com.zhao.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @program: mybatis-plus
 * @description: 日期自动填充处理
 * @author: Stevezhao
 * @create: 2021-07-12 15:12
 */
@Slf4j //开启日志
@Component  //加入springioc容器
public class MyMetaObjectHandler implements MetaObjectHandler {

    //插入时候的填充策略
    @Override
    public void insertFill(MetaObject metaObject) {
           log.info("start insert fill....");
           this.setFieldValByName("create_time",new Date(),metaObject);
           this.setFieldValByName("update_time",new Date(),metaObject);
    }

    //更新时的填充策略
    @Override
    public void updateFill(MetaObject metaObject) {
        log.info("start update fill....");
        this.setFieldValByName("update_time",new Date(),metaObject);
    }
}
